/**
 * 
 */
package com.effectivsocial.domain;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;

import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.JoinTable;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import org.hibernate.envers.Audited;
import org.hibernate.envers.NotAudited;
import org.joda.time.DateTime;
import java.util.List;
import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.constraints.Email;
import javax.validation.constraints.Size;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;


/**
 * @author Dhrubo
 * 
 */
@Audited
@Entity
@Table(name = "t_user")
public class User implements Serializable{
	private static final long serialVersionUID = 1L;
	
	@Getter @Setter
	@Id
	@GeneratedValue(generator = "uuid")
	@GenericGenerator(name = "uuid", strategy = "uuid2")
	@Column(name = "user_id", updatable = false, nullable = false, unique = true)
	private String id;
	
	
	@NotEmpty(message="First Name is required.")
	@Size(min = 2, max = 50)
	@Getter @Setter
	@Column(name="first_name" ,nullable=false , length=50)
	private String firstName;
	
	@Getter @Setter
	@Column(name="last_name" ,nullable=false , length=50)
	private String lastName;
	
	@NotEmpty(message="Email is required.")
	@Email(message="Invalid email address.")
	@Getter @Setter
	@Column(name="email",unique=true ,nullable=false, length=100)
	private String email;
	
	@NotEmpty(message="Password is required.")
	@Size(min = 6)
	@Getter @Setter
	@Column(name="password",unique=false ,nullable=false, length=500)
	private String password;
	
	@Getter @Setter
	@Temporal(TemporalType.TIMESTAMP)
	@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
	@Column(name = "created_date", nullable = false, updatable = false)
	private DateTime createdDate;
	
	@Getter @Setter
	@Temporal(TemporalType.TIMESTAMP)
	@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
	@Column(name = "last_modified_date", nullable = false, updatable = false)
	private DateTime lastModifiedDate;
	
	@Getter @Setter
	@Temporal(TemporalType.TIMESTAMP)
	@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
	@Column(name = "activation_date", nullable = true, updatable = false)
	private DateTime activationDate;
	
	@Getter @Setter
	@Column(name="deleted" ,nullable=false)
	private boolean deleted;
	
	@Getter @Setter
	@Column(name="locked" ,nullable=false)
	private boolean locked;
	
	@NotAudited
	@Getter @Setter
    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
	@JoinTable(name= "t_user_role",
           joinColumns = {@JoinColumn(name="user_id")},
           inverseJoinColumns = {@JoinColumn(name="role_id")})  
	private List<Role> roles;
	
	
	

	@NotNull
    @Valid
	@NotAudited
	@Getter @Setter
	@OneToOne
	private Company company;
	
}
